package com.chixing.controller;

import com.chixing.service.EvaluateService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class EvaluateController {
    @Autowired
    private EvaluateService evaluateService;

    // 根据主键查询评价
    @GetMapping(value = {"evaluate/{carId}/page/{pageNum}","evaluate/{carId}/page"})
    @ResponseBody
    public ServerResponse getEvaluateById(@PathVariable("carId") Integer carId,
                                          @PathVariable(value = "pageNum",required = false) Integer pageNum){
        if (pageNum == null)
            pageNum = 1;

        return evaluateService.getEvaluateByCarId(carId,pageNum);
    }
    @PutMapping("evaluate/{evaluateId}/{custId}/{status}")
    @ResponseBody
    public ServerResponse updateEvaluateByCarId(@PathVariable ("evaluateId")Integer evaluateId,
                                                @PathVariable("custId") Integer custId,
                                                @PathVariable("status") Integer status){
        return evaluateService.updateEvaluateByCarId(evaluateId,custId,status);
    }

    @GetMapping("evaluate/praised")
    @ResponseBody
    public ServerResponse getEvaluatePraisedStatus(Integer evaluateId,Integer custId){
        return evaluateService.getEvaluatePraisedStatus(evaluateId,custId);
    }
}
